//JavaScript Framework 2.0 Code
try {
	Type.registerNamespace('com.yonyou.dxyma.ConfirmController');
	com.yonyou.dxyma.ConfirmController = function() {
		com.yonyou.dxyma.ConfirmController.initializeBase(this);
		this.initialize();
	}
	function com$yonyou$dxyma$ConfirmController$initialize() {
	}

	function com$yonyou$dxyma$ConfirmController$evaljs(js) {
		eval(js)
	}
var data;
var material_pk;
var pk_machineorder;
var scanParmater;
	//界面打开后加载数据
	function com$yonyou$dxyma$ConfirmController$pageOnLoad(sender, args) {
		// 加载机台物料信息
		data = $param.getJSONObject("data");
		//$alert(str);
		var jt_code = data["mac"];
		var parmater = data["data"];
		var zl_code = parmater["material_code"];
		var cp_name = parmater["material_name"];
		material_pk = parmater["material_pk"];
		pk_machineorder = parmater["pk_machineorder"];
		$id("jtlabel").set("value",jt_code);
		$id("zllabel").set("value",zl_code);
		$id("cplabel").set("value",cp_name);
		var scanString = $param.getString("scannerData");
		try{
			scanParmater = JSON.parse(scanString);
			//$alert(scanString);
			if(scanParmater["material_name"]==cp_name){
				$id("gyslabel").set("value",scanParmater["gys"]);
				$id("gzlabel").set("value",scanParmater["gz"]);
				$id("lphlabel").set("value",scanParmater["batchcode"]);
				$id("jhlabel").set("value",scanParmater["jh"]);
				$id("weightlabel").set("value",scanParmater["material_weight"]);
			}else{
				$id("gyslabel").set("value",scanParmater["gys"]);
				$id("gzlabel").set("value",scanParmater["gz"]);
				$id("lphlabel").set("value",scanParmater["batchcode"]);
				$id("jhlabel").set("value",scanParmater["jh"]);
				$id("weightlabel").set("value",scanParmater["material_weight"]);
				$id("label1").set("value","不匹配");
				$id("label1").set("background","#ff0000");
				$id("button2").set("value","重新扫码");
			}
		}catch(err){
			$alert("二维码信息错误，请检查");
			$id("label1").set("value","不匹配");
			$id("label1").set("background","#ff0000");
			$id("button2").set("value","重新扫码");
		}
	}
function com$yonyou$dxyma$ConfirmController$button2_onclick(sender, args){
	var parmater = data["data"];
	if($id("label1").get("value")=="匹配"){
		var myparam = {
			"actiontype" : "66603",
			"param" : {
				"pk_machineorder" : pk_machineorder,
				"pk_material" : material_pk,
				"nums" : scanParmater["material_weight"],
				"batchcode" : scanParmater["batchcode"]
			}
		};
		var ip = $param.getString("ip");
		var port = $param.getString("port");
		
		$service.writeConfig({
            "host" : ip,//向configure中写入host键值
            "port" : port //向configure中写入port键值
        })
		
		$service.callAction({
            "viewid" : "com.yonyou.mes.HttpCaller",//部署在MA上的Controller的包名
            "action" : "call",//后台Controller的方法名,
            "params" : {"myparam":myparam},//自定义参数，json格式
            "autoDataBinding" : false,//请求回来的数据会在Context中，是否进行数据绑定，默认不绑定
            "contextmapping" : "result",//将返回结果映射到指定的Context字段上，支持fieldName和xx.xxx.fieldName字段全路径，如未指定contextmapping则替换整个Context
            "callback" : "callsuccess()",//请求成功后回调js方法
            "error" : "callerror()"//请求失败回调的js方法
        })
	}else{
		$view.open({
        	"viewid" : "com.yonyou.dxyma.Scan",//目标页面（首字母大写）全名
        	"isKeep" : "false",
        	"data": data
    	})
	}
}

function callsuccess(){
	var result = $ctx.get("result");
	//$alert(result);
	var jsonobj = JSON.parse(result);
	//$alert(jsonobj);
	var status = jsonobj["statuscode"];
	//$alert(status);
	if(status==0){
		$alert("投料成功");
		/*var machine = {
			"mac" : data["mac"],
			"pk" : data["pk"] 
		}
		$view.open({
        	"viewid" : "com.yonyou.dxyma.Infos",//目标页面（首字母大写）全名
        	"isKeep" : "false",
        	"data": machine
    	})*/
    	$view.close({
            "resultCode": "15",//当resultCode为15时，可以响应父页面的callback
            "num": scanParmater["material_weight"]//返回结果，result1为自定义键值
        });
	}else{
		$alert(jsonobj["errinfo"]);
		$alert("投料失败，请重新投料");
	}
}

function callerror(){
	$alert("投料请求失败，请检查网络连接");
}

function com$yonyou$dxyma$ConfirmController$onkeydown(sender, args){
	var parmater = data["data"];
	$view.close({
        "resultCode": "16",//当resultCode为15时，可以响应父页面的callback
    });
	/*$view.open({
        "viewid" : "com.yonyou.dxyma.Scan",//目标页面（首字母大写）全名
        "isKeep" : "false",
        "data": data
    })*/
}	
com.yonyou.dxyma.ConfirmController.prototype = {
    onkeydown : com$yonyou$dxyma$ConfirmController$onkeydown,
    button2_onclick : com$yonyou$dxyma$ConfirmController$button2_onclick,
		pageOnLoad : com$yonyou$dxyma$ConfirmController$pageOnLoad,
		initialize : com$yonyou$dxyma$ConfirmController$initialize,
		evaljs : com$yonyou$dxyma$ConfirmController$evaljs
	};
	com.yonyou.dxyma.ConfirmController.registerClass('com.yonyou.dxyma.ConfirmController', UMP.UI.Mvc.Controller);
} catch(e) {
	$e(e);
}
function show() {
	alert("绑定字段的值：" + $id("wtogglebuttongroup0").getAttribute("selectedValue"));
}
